package org.jivesoftware.smackx.packet;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;
import org.jivesoftware.smack.packet.IQ;

public class Time extends IQ
{
  private static DateFormat displayFormat;
  private static SimpleDateFormat utcFormat = new SimpleDateFormat("yyyyMMdd'T'HH:mm:ss");
  private String display;
  private String tz;
  private String utc = null;

  static
  {
    displayFormat = DateFormat.getDateTimeInstance();
  }

  public Time()
  {
    this.tz = null;
    this.display = null;
  }

  public Time(Calendar paramCalendar)
  {
    this.tz = null;
    this.display = null;
    TimeZone localTimeZone = paramCalendar.getTimeZone();
    this.tz = paramCalendar.getTimeZone().getID();
    this.display = displayFormat.format(paramCalendar.getTime());
    this.utc = utcFormat.format(new Date(paramCalendar.getTimeInMillis() - localTimeZone.getOffset(paramCalendar.getTimeInMillis())));
  }

  public String getChildElementXML()
  {
    StringBuilder localStringBuilder = new StringBuilder();
    localStringBuilder.append("<query xmlns=\"jabber:iq:time\">");
    if (this.utc != null)
      localStringBuilder.append("<utc>").append(this.utc).append("</utc>");
    if (this.tz != null)
      localStringBuilder.append("<tz>").append(this.tz).append("</tz>");
    if (this.display != null)
      localStringBuilder.append("<display>").append(this.display).append("</display>");
    localStringBuilder.append("</query>");
    return localStringBuilder.toString();
  }

  public String getDisplay()
  {
    return this.display;
  }

  public Date getTime()
  {
    Object localObject2;
    if (this.utc == null)
    {
      localObject2 = null;
      return localObject2;
    }
    Object localObject1 = null;
    try
    {
      Calendar localCalendar = Calendar.getInstance();
      localCalendar.setTime(new Date(utcFormat.parse(this.utc).getTime() + localCalendar.getTimeZone().getOffset(localCalendar.getTimeInMillis())));
      Date localDate = localCalendar.getTime();
      localObject1 = localDate;
      localObject2 = localObject1;
    }
    catch (Exception localException)
    {
      while (true)
        localException.printStackTrace();
    }
  }

  public String getTz()
  {
    return this.tz;
  }

  public String getUtc()
  {
    return this.utc;
  }

  public void setDisplay(String paramString)
  {
    this.display = paramString;
  }

  public void setTime(Date paramDate)
  {
    this.utc = utcFormat.format(new Date(paramDate.getTime() - TimeZone.getDefault().getOffset(paramDate.getTime())));
  }

  public void setTz(String paramString)
  {
    this.tz = paramString;
  }

  public void setUtc(String paramString)
  {
    this.utc = paramString;
  }
}